/*
  ID: nemokin1
  PROG: maze1
  LANG: C++
*/
#include <vector>
#include <list>
#include <assert.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <fstream>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int>  ii;
typedef long double ld;
const int INF = 1000000000;

char rr[300][300];
int visited[300][300];

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int main() {
    //freopen("maze1.in","r",stdin);freopen("maze1.out","w",stdout);
    int W,H;
    int ret = 0;
    
    cin >> H >> W;
    string s;
    getline(cin,s);
    for(int i = 0; i < 2*W+1; i++){
	getline(cin,s);
	for(int j = 0; j < 2*H+1; j++) rr[i][j] = s[j];
    }
    // for(int i = 0; i < 2*H+1; i++){
    // 	for(int j = 0; j < 2*W+1; j++){
    // 	    cout << rr[i][j];
    // 	}
    // 	cout << endl;
    // }
    
    for(int i = 1; i < 2*W+1; i+=2){
	for(int j = 1; j < 2*H+1; j+=2){
	    memset(visited,0,sizeof(visited));
	    bool test = true;
	    queue<int> q;
	    q.push(i);q.push(j);q.push(0);
	    //cout << i << " " << j << endl;
	    while(!q.empty()){
		if(test = false) break;
		int first = q.front();q.pop();
		int second = q.front();q.pop();
		int cnt = q.front();q.pop();
		//cout<<"("<<first<<","<<second<<")"<<cnt<<endl;
		// if(first < 0 || first > 2*W || second < 0 || second > 2*H){
		//     checkMax(ret,cnt);
		//     break;
		// }
		//if(visited[first][second]) continue;
		//visited[first][second] = 1;
		cnt++;
		for(int i = 0; i < 4; i++){
		    int x = first+dx[i];
		    int y = second+dy[i];
		    if(rr[x][y] == ' '){
			if(x+dx[i] < 0 || x+dx[i] > 2*W || y+dy[i] < 0 || y+dy[i] > 2*H){
			    checkMax(ret,cnt);
			    test = false;
			    break;
			}
			if(visited[x+dx[i]][y+dy[i]]) continue;
			visited[x+dx[i]][y+dy[i]] = 1;
			q.push(x+dx[i]);q.push(y+dy[i]);q.push(cnt);
		    }
		}
	    }
	}
    }
    cout << ret << endl;
}

    

